<?php

class Commodities extends Controller {

	function __construct() {
		parent::Controller();	
	}
	
	function index() {
		//Use this for your home page
		$data['title'] = "imerchant: Commodity's Home";
		$data['main'] = 'commodities/home';
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	function add_commodities() {
		//Add commodities
		$data['title'] = "imerchant: Add commodities";
		$data['main'] = 'commodities/add_commodities';
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	function send() {
		if($this->input->post('name')) {
			$this->Mcommodities->addCommodity();
			$data['title'] = "imerchant";
			$data['main'] = 'commodities/sent';
			$this->load->vars($data);
			$this->load->view('template');
		} else {
		 show_error("This is not working");
		} 
	}
	
	function view_commodities() {
		//View commodities
		$data['title'] = "imerchant";
		$data['main'] = 'commodities/view_commodities';
		$data['result'] = $this->Mcommodities->getAllCommodities();
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	function delete() {
		//Delete commodities
		$del_rows=0;
		if($this->input->post('delete')) {
			@$item=$_POST['item'];
			while (list ($key, $sel_id) = @each ($item)) { 
				$this->Mcommodities->deleteCommodities($sel_id);
				$del_rows++; 
			} 
			
			$data['main'] = 'commodities/delete';
			$data['del_rows'] = $del_rows;
			$this->load->vars($data);
			$this->load->view('template');
			
		} else {
		 show_error("This is not working");
		} 
	}
	
	function edit($id) {
		//Edit commodities
		$data['result'] = $this->Mcommodities->getCommodity($id);
		$data['main'] = 'commodities/edit';
		$this->load->vars($data);
		$this->load->view('template');	
	}
	
	function update() {
		//update commodities
		$id = $_POST['id'];
		if($this->input->post('update')) {
			$this->Mcommodities->updateCommodity($id);
			$data['title'] = "imerchant";
			$data['main'] = 'commodities/update';
			$this->load->vars($data);
			$this->load->view('template');
		} else {
		 show_error("This is not working");
		} 
	}
}

/* End of file commodities.php */